import type { GetListParams, GetListResponse } from "./request";
import { apiExtend, request } from "./request";

export interface AddCurdParams {
  a: string;
  b: number;
  c: boolean;
}

/** 增加 */
export const addCurdData = (data: AddCurdParams) => {
  return request({
    url: "/curd/add",
    method: "POST",
    data,
  });
};

/** 删除 */
export const deleteCurdData = (data: { id: number }) => {
  return request({
    url: "/curd/delete",
    method: "POST",
    data,
  });
};

export interface EditCurdParams extends AddCurdParams {
  id: number;
}

/** 编辑 */
export const editCurdData = (data: EditCurdParams) => {
  return request({
    url: "/curd/edit",
    method: "POST",
    data,
  });
};

export type CurdDataDetail = EditCurdParams;
/** 获取详情 */
export const getCurdDataDetail = apiExtend((params: { id: number }) => {
  return request<CurdDataDetail>({
    url: "/curd/detail",
    method: "GET",
    params,
  });
});

export type CurdListParams = AddCurdParams;

export type CurdListItem = CurdDataDetail;

/** 获取列表 */
export const getCurdDataList = apiExtend(
  (params: GetListParams<CurdListParams>) => {
    return request<GetListResponse<CurdListItem>>({
      url: "/curd/list",
      method: "GET",
      params,
    });
  },
);
